Linux System Maintenance: Disk Cleanup and Space Management
This article explains the necessity and methods of disk cleanup and space management for Linux servers. When disk space is insufficient, the system may become slow, applications cannot be updated, and even services may be affected, so regular cleanup and management are necessary. First, diagnose space usage: use `df -h` to check overall disk usage, `du -sh` to locate large directories, and `find` to search for large files (e.g., files exceeding 100MB). For cleanup, log files (e.g., `/var/log`) are a major space consumer. They can be automatically rotated using `logrotate` or manually emptied/deleted. System cache can be released by syncing data with `sync` and then setting `sysctl -w vm.drop_caches=3`. Temporary files (`/tmp`, `/var/tmp`) and APT cache (`apt clean`) can also be safely cleaned. Redundant files in user directories should be deleted after confirmation. If space remains insufficient after cleanup, a new disk can be mounted (requires formatting, creating a mount point, and configuring `/etc/fstab`). Partition expansion should be done cautiously with data backup. Daily maintenance suggestions: regularly check disk usage (cleanup is required when exceeding 80%), configure log rotation, avoid storing data in the root directory, and do not arbitrarily delete system files. The core is "locate -"
Read MoreBeginner's Guide: Linux Disk Space Cleaning Tips
When the disk space on a Linux server is insufficient, you can resolve it by following these steps: First, execute `df -h` to check partition usage, focusing on the root directory or system directories like `/var`. Next, use `du -sh` to locate large directories (e.g., `/var/cache`), and `find / -type f -size +100M 2>/dev/null` to search for large files. For targeted cleanup: Logs in `/var/log` can be rotated using logrotate or old compressed packages deleted; temporary cache files in `/tmp` and `/var/tmp` can be cleared after running `sync`, or system cache can be released by `echo 3 > /proc/sys/vm/drop_caches`; uninstall unnecessary software packages (via `yum` or `apt`); and large files in user directories (e.g., under `/home`) can be directly deleted. **Note**: Do not delete system-critical files. Confirm no programs are using files before deletion, and follow the procedures for safe and efficient operation.
Read More